package com.iflytek.sbd.aspect;

import com.iflytek.sbd.po.Cache;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @program: sbd
 * @description:
 * @author: 陈英俊
 * @create: 2022-01-10 14:24
 */
//@Aspect
//@Component
//public class LoginAspect {
//
//
//    @Autowired
//    private Cache cache;
//
//    @Pointcut("execution(* com.iflytek.sbd.controller.*.*(..)))")
//    public void loginAspect() {
//    }
//
//    @Before("loginAspect()")
//    public void doBefore(JoinPoint joinPoint) throws ServletException, IOException {
//        ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
//        HttpServletRequest request = attributes.getRequest();
//        HttpServletResponse response = attributes.getResponse();
//        if (cache.getMap().size() == 0 && !request.getRequestURL().toString().equals("/login/login")) {
//            request.getRequestDispatcher("/static/login.html").forward(request, response);
//        }
//    }
//}
